package com.cms.demo.config;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import javafx.util.Builder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.GsonHttpMessageConverter;

import java.lang.reflect.Modifier;

/**
 * 使用 Gson进行日期的转换
 * @author wangning
 * @create 2021-04-26 9:37
 */
@Configuration
public class GsonConfig {
	@Bean
	public GsonHttpMessageConverter gsonHttpMessageConverter() {
		GsonHttpMessageConverter converter = new GsonHttpMessageConverter();
		GsonBuilder gsonBuilder = new GsonBuilder();
		gsonBuilder.setDateFormat("yyyyMMdd");
		gsonBuilder.excludeFieldsWithModifiers(Modifier.PROTECTED);
		Gson gson = gsonBuilder.create();
		converter.setGson(gson);
		return converter;
	}
}
